<!--
* description: 采购管理-订单审核配置项
* author: hzm
* createdDate: 2021-1-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="dynamicApiConfigs"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :callback-obj="callbackObj"
      :dynamic-is-show-select="true"
      :dynamic-is-init-table="true"
      :dynamic-is-fix-choose="false"
      :dynamic-is-fix-index="false"
      :dynamic-api-style="'restful'"
      :is-show-pagination="true"
    >
      <template #reviewOrder="scope">
        <el-input-number
          :key="'num'"
          v-model="scope.row['reviewOrder']"
          :step="1"
          :min="1"
          step-strictly
        />
      </template>
    </one-table-template>
  </div>
</template>

<script>
import { formMixins } from '@/components/mixins/formMixins'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { orgApis } from '@/api/paSparePartsManagement'

export default {
  name: 'OrderReview',
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins, formMixins],
  data() {
    return {
      selectiondata: [],
      dynamicApiConfigs: orgApis.queryData,
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'businessTypeName',
              label: '业务类型',
              align: 'center'
            },
            {
              prop: 'businessAllocationTypeName',
              label: '业务分配类型',
              align: 'center'
            },
            // {
            //   prop: 'isLackReview',
            //   label: '是否缺件审核',
            //   align: 'center',
            //   isShowLabel: true,
            //   isComponent: true,
            //   comps: [
            //     {
            //       compKey: 'audit',
            //       codeField: 'isLackReview',
            //       component: () => import('@/components/org/checkBox')
            //     }
            //   ]
            // },
            {
              prop: 'isLackAdd',
              label: '是否产生欠拨',
              align: 'center',
              isShowLabel: true,
              isComponent: true,
              comps: [
                {
                  compKey: 'isLackAdd',
                  codeField: 'isLackAdd',
                  component: () => import('@/components/org/checkBox')
                }
              ]
            },
            {
              prop: 'isAutoReview',
              label: '是否自动分配',
              align: 'center',
              isShowLabel: true,
              isComponent: true,
              comps: [
                {
                  compKey: 'audit',
                  codeField: 'isAutoReview',
                  component: () => import('@/components/org/checkBox')
                }
              ]
            },
            {
              prop: 'isDeliveryAdd',
              label: '是否写入日期',
              align: 'center',
              isShowLabel: true,
              isComponent: true,
              comps: [
                {
                  compKey: 'isDeliveryAdd',
                  codeField: 'isDeliveryAdd',
                  component: () => import('@/components/org/checkBox')
                }
              ]
            },
            {
              prop: 'isConfirmAmount',
              label: '分配前判断金额',
              align: 'center',
              isShowLabel: true,
              isComponent: true,
              comps: [
                {
                  compKey: 'audit',
                  codeField: 'isConfirmAmount',
                  component: () => import('@/components/org/checkBox')
                }
              ]
            },
            {
              prop: 'reviewOrder',
              label: '审核顺序',
              align: 'center',
              isSlot: true
            }
            // {
            //   prop: "warehouseName",
            //   label: "分配仓库",
            //   align: "center",
            //   // isShowLabel: true,
            //   oFields: 'warehouseName,warehouseId,warehouseCode',
            //   isComponent: true,
            //   comps: [
            //     {
            //       compKey: "audit",
            //       codeField: "warehouseName",
            //       textField: "warehouseName",
            //       customObj: {
            //         api: orgApis.getWarehouse,
            //         defOptionFields:['warehouseId','warehouseName']
            //       },
            //       component: () => import("@/components/org/commonSelect"),
            //       type: "dropdownList",
            //     },
            //   ],
            // },
          ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 库存状态
            {
              compKey: 'compKey1',
              labelName: '业务类型：',
              codeField: 'businessType',
              textField: 'partRepairTypeName',
              customObj: {
                api: orgApis.businessType
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: true,
              span: 6
            },
            {
              compKey: 'compKey2',
              labelName: '业务分配类型：',
              codeField: 'businessAllocationType',
              textField: 'partRepairTypeName',
              customObj: {
                api: orgApis.businessAllocationType
              },
              component: () => import('@/components/org/commonSelect'),
              type: 'dropdownList',
              isMust: true,
              span: 6
            }
          ],
      tableButtons: [
        {
          conmpKey: 'btenKey1',
          type: 'primary',
          size: 'small',
          text: '查询',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          position: 'right'
        },
        {
          conmpKey: 'btenKey3',
          type: '',
          size: 'small',
          text: '保存',
          name: 'save',
          clickEvent: () => this.save(),
          position: 'right'
        },
        {
          conmpKey: 'btenKey2',
          type: '',
          size: 'small',
          text: '重置',
          name: 'reset',
          clickEvent: () => this.reset(),
          position: 'right'
        }
      ],
      formField: this.$utils.getFormField(this, {
        businessType: '',
        businessAllocationType: ''
      }),
      callbackObj: {
        // 手动勾选网格时，拿到勾选网格的数据
        onCheckSelectChange: (selection, row) => {
          this.selectiondata = selection
        }
      }
    }
  },
  mounted() {
    // this.queryTable(1)
    this.$refs.multipleTable.list = [
      {
        index: 1
      }
    ]
  },
  methods: {
    save() {
      const that = this
      let infoQue = []
      infoQue = this.selectiondata
      // this.selectiondata.forEach(function (val, index) {
      //   infoQue.push({
      //     isLackReview: val.isLackReview,
      //     isLackAdd: val.isLackAdd,
      //     isAutoReview: val.isAutoReview,
      //     isDeliveryAdd: val.isDeliveryAdd,
      //     isConfirmAmount: val.isConfirmAmount,
      //     distributionWarehouse: val.warehouseCode,
      //     assignReviewSetId: val.assignReviewSetId
      //   });
      // });
      if (infoQue.length == 0) {
        this.$message({
          message: '请勾选数据后进行保存',
          type: 'success',
          duration: 2000
        })
      } else {
        const queryObj = {
          apiConfig: orgApis.save,
          // 条件/实体参数（变量），根据typeParam中的定义配置
          variables: {
          // 当前中台使用的名称有dataInfo、info，具体查看API文档
            dataInfo: infoQue
          }
        }
        // 转换了中台请求格式数据
        var paramD = that.$getParams(queryObj)
        // 调用中台API方法（可复用）
        that.$requestAPI(paramD).then((response) => {
          if (response.result === '0') {
            return
          }
          var getResult = response
          if (getResult.result === '1') {
            that.$message({
              message: '保存成功',
              type: 'success',
              duration: 2000
            })
            this.selectiondata = []
            that.queryTable(1)
          } else {
            that.$message({
              message: getResult.msg,
              type: 'warning',
              duration: 2000
            })
          }
        })
      // }
      }
    }

  }
}
</script>

<style>
</style>
